<?php
	check_login();
	$a = getAction();

	switch($a) {
		case 'index':
			$promoterId = $_SESSION['web_cadmin']['promoter_id'];

			$sql = " select *  from " . table('order') . " where status <> '-1' and promoter_id = '$promoterId' order by id desc";
			$url="cadmin.php?m=order";

			$rscount=$db->getOne("select count(1) from ($sql) temp");
			$pagesize=20;
			$page=max(1,intval($_GET['page']));
			$start=($page-1)*$pagesize;
			$sql.=" limit $start,$pagesize";
			
			$list = $db->getAll($sql);
			
			for ($i = 0; $i < count($list); $i++) {
				$list[$i]["user"] = $db->getRow("select * from " . table("user") . " where openid = '" .$list[$i]["openid"] . "'");
				$list[$i]["status_name"] = ORDER_STATUS::getOrderStatusName($list[$i]["status"]);
				
				if ($list[$i]["status"] == ORDER_STATUS::FAIL) {
					$list[$i]["fail_reason"] = MAI_STATUS_CODE::$STATUS_CODE_ARRAY[$list[$i]["mai_status_code"]];
				}
				
				$list[$i]["total_fee"] = $list[$i]["total_fee"] / 100.0;
			}

			$smarty->assign("pagelist",multipage($rscount,$pagesize,$page,$url));
			$smarty->assign("list", $list);

			$smarty->display("order.html");
			break;	
}
?>